package countor;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 并发计数器计数,最大计数Long.MAX_VALUE
 * @author dingnate
 */
public class AtomCountor<T> implements ICountor<T> {
	private T owner;
	// Atom实现方式
	private AtomicLong counter = new AtomicLong(0);

	public AtomCountor(T owner) {
		super();
		this.owner = owner;
	}

	public final void incr() {
		incr(1);
	}

	public final void incr(long increment) {
		counter.addAndGet(increment);
	}

	public final Long getCount() {
		return counter.longValue();
	}

	public final T getOwner() {
		return owner;
	}

	@Override
	public String toString() {
		return "Counter [" + "count=" + getCount() + ", owner=" + owner + "]";
	}
}